<?php

class Fields_Admin_Model extends Model {

    function Fields_Admin_Model()
    {
        parent::Model();
    }
    
    public function get($page = false) {
        
        $page = ($page === false) ? $this->uri->current_uri() : $page;
        
        return $this->db->get_where('modul_page', array('pag_uri' => $page));
    }
    
    public function get_byid($id) {
        
        return $this->db->get_where('modul_page', array('pag_id' => $id));
    }
    
    public function get_all($limit = NULL, $offset = NULL) {
        
        return $this->db->get('fields', $limit, $offset);
    }
    
    public function count_all() {
        
        return $this->db->count_all('modul_page');
    }
    
    public function add($uri, $title, $text) {
        
        $data = array(
            'pag_uri'   => $uri,
            'pag_title' => $title,
            'pag_text'  => $text
        );
        
        return $this->db->insert('modul_page', $data); 
    }
    
    public function update($id, $uri, $title, $text) {
        
        $data = array(
            'pag_uri'   => $uri,
            'pag_title' => $title,
            'pag_text'  => $text
        );
        
        return $this->db->update('modul_page', $data, array('pag_id' => $id));
    }
    
    public function delete($id) {
        
        return $this->db->delete('modul_page', array('pag_id' => $id)); 
    }
}